import { ListBase } from 'src/components/list_base_abs';
import { Component, Emit, Prop, Provide } from 'vue-property-decorator'

import { updateSelection } from 'src/utils/list_utils';
import OperatorHandler from 'src/views/acc_manage/operator_handler';
import { OrganizationConst } from "src/consts/organization_const";
import { PopupName } from "src/consts/popup_const";


@Component({})
export default class OrgAccPanel extends ListBase {
    name: string = 'OrgAccPanel';
    queryData: QueryHandler;
    selectList: any = []
    selectState: any = {}
    itemData: any = []
    footerFlag: boolean = true;
    mainData: any;

    initData(that?: any) {
        that.myState = WLStore().state.orgAcc;
        that.selectState = {};
        that.selectState["data_list"] = [];
        that.itemData = [];
        that.selectList = [];
        that.selection = [];
        that.mainData = {};
    }

    getListData(): void {
    }

    mounted(): void {
    }

    doQuery(isAdv: Boolean): void {
        var obj: any = {}
        for (let key in this.mainData) {
            if (this.mainData[key]) {
                obj[key] = this.mainData[key]
            }
        }

        obj["curr_page"] = 1
        obj["page_size"] = 9999
        obj.select = this.selectState.data_list
        WLDispatch(OrganizationConst.DispatchOrgAcc, obj);
    }

    handleSelectionChange(list: any[]): void {
        updateSelection(this.selection, list);
        console.log("this selection", this.selection, list);
    }

    selectChange(list: any[]): void {
        updateSelection(this.selectList, list);
        console.log("this selectionList", this.selectList, list);
    }

    rowClassName(data: any): string {
        if (data.row.selected) {
            return 'selected_row';
        }
        return '';
    }

    editMem(): void {
        if (isNoEmpty(this.selectState.data_list)) {
            WLCommit(OrganizationConst.CommitOrgShowListAcc, this.selectState.data_list)
        } else {
            WLLib.panel(PopupName.Org_Acc_Panel).close()
        }
    }

    add_next(data: any): void {
        var list = this.myState.data_list.slice(0)

        for (let i = 0; i < this.myState.data_list.length; i++) {
            for (let k = 0; k < this.selection.length; k++) {
                if (list[i] && this.selection[k].id == list[i].id) {
                    this.itemData.push(list[i])
                    list.splice(i, 1)
                    i -= 1
                }
            }
        };
        this.myState.data_list = list
        this.selectState["data_list"] = this.itemData
    }

    add_up(data: any): void {
        var list = this.selectState.data_list.slice(0)

        for (let i = 0; i < this.selectState.data_list.length; i++) {
            for (let k = 0; k < this.selectList.length; k++) {
                if (list[i] && this.selectList[k].id == list[i].id) {
                    this.myState.data_list.push(list[i])
                    list.splice(i, 1)
                    i -= 1
                }
            }
        };

        this.selectState.data_list = list
    }
}